package longrise.phone.com.bjjt_henan.Utils;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.longrise.LEAP.Base.Objects.EntityBean;
import com.longrise.android.loaddata.newloaddata.LoadDataManager4;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerCar;
import com.longrise.android.loaddata.newloaddata.LoadDataManagerFather;

import java.io.File;

import longrise.phone.com.bjjt_henan.BuildConfig;
import longrise.phone.com.bjjt_henan.Constant.URLConstant;
import longrise.phone.com.bjjt_henan.R;


/**
 * Created by Administrator on 2016/5/14.
 */
public class ApiImpI {

    private static ApiImpI instance;

    private String BASE_URL;

    private String KCKP_URL;

    private Handler mHandler;
    private Context mContext;

    private ApiImpI(Context context) {
        BASE_URL = context.getResources().getString(R.string.kckpServerUrl);
        KCKP_URL = context.getResources().getString(R.string.kckpServerUrl);
        mHandler = new Handler(Looper.getMainLooper());
        this.mContext = context;
    }

    public static ApiImpI getInstance(Context context) {
        if (instance == null) {
            synchronized (ApiImpI.class) {
                if (instance == null) {
                    instance = new ApiImpI(context);
                }
            }
        }
        return instance;
    }

    /**
     * 请求注册验证码
     *
     * @param phonenum:手机号码
     * @param imgCode:图片验证码
     * @param imgid:图片id
     * @param callBack：回调接口
     */
    public void getValidCode(String phonenum, String imgCode, String imgid, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("mobilenumber", phonenum);
        bean.set("imgcode", imgCode);
        bean.set("imgid", imgid);
        run(BASE_URL, URLConstant.VALIDCODE, bean, callBack);
    }


    /**
     * 请求图片验证码
     *
     * @param callBack：回调接口
     */
    public void picCodeCreate(RequestCallBack callBack) {
        run(BASE_URL, URLConstant.CODECREATE, null, callBack);
    }

    /**
     * 请求修改手机号码验证码
     *
     * @param phonenum:手机号码
     * @param callBack：回调接口
     */
    public void getPhoneCode(String phonenum, String imgCode, String imgid, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("mobilenumber", phonenum);
        bean.set("imgcode", imgCode);
        bean.set("imgid", imgid);
        run(BASE_URL, URLConstant.PHONECODE, bean, callBack);
    }

    /**
     * 登录
     *
     * @param userflag:用户名
     * @param pwd:密码
     * @param callBack：回调接口
     */
    public void login(String userflag, String pwd, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("userflag", userflag);
        bean.set("password", pwd);
        run(BASE_URL, URLConstant.LOGIN, bean, callBack);
    }

    /**
     * 只用手机号登录
     *
     * @param phone:手机号
     * @param code:密码
     * @param callBack：回调接口
     */
    public void loginByPhone(String phone, String code, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("phonenumber", phone);
        bean.set("code", code);
        run(BASE_URL, URLConstant.LOGIN_PHONE, bean, callBack);
    }

    /**
     * 只用手机号注册
     *
     * @param phonenum:手机号码
     * @param code:验证码
     * @param longitude:经度
     * @param latitude:纬度
     * @param callBack：回调接口
     */
    public void registeredByPhone(String phonenum, String code, String longitude, String latitude,
                                  RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("phonenumber", phonenum);
        bean.set("code", code);
        bean.set("caselon", longitude);
        bean.set("caselat", latitude);
        bean.set("clientmac", "6");
        run(BASE_URL, URLConstant.REGISTER_PHONE, bean, callBack);
    }

    /**
     * 查询未接收的推送消息
     *
     * @param appcaseno:移动报案号
     * @param msgtype:消息类型
     * @param token:验证字符串
     * @param username:用户名
     * @param callBack：回调接口
     */
    public void searchUnMsg(String appcaseno, String msgtype, String username,
                            String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", appcaseno);
        bean.set("msgtype", msgtype);
        bean.set("uid", username);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.SEARCH_UNRECEIVEMSG, bean, callBack);
    }

    /**
     * 实时接收到消息后调用
     *
     * @param id:案件id
     * @param msgtype:消息类型
     * @param token:验证字符串
     * @param username:新密码
     * @param callBack：回调接口
     */
    public void receiveCallBack(String id, String msgtype, String username,
                                String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("id", id);
        bean.set("msgtype", msgtype);
        bean.set("uid", username);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.RECEIVEMSG_CALLBACK, bean, callBack);
    }

    /**
     * 修改联系电话
     *
     * @param userflag:用户名
     * @param oldPhonenum:旧手机号
     * @param newPhonenum:手机号码
     * @param code:验证码
     * @param token:验证字符串
     * @param pwd:密码
     * @param callBack：回调接口
     */
    public void modifyPhone(String userflag, String oldPhonenum, String newPhonenum,
                            String code, String token, String pwd, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("mobilephoneold", oldPhonenum);
        bean.set("mobilephone", newPhonenum);
        bean.set("code", code);
        bean.set("token", token);
        bean.set("password", pwd);
        run(BASE_URL, URLConstant.MODIFYPHONE, bean, callBack);
    }

    /**
     * 绑定机动车
     *
     * @param cartype:车型
     * @param carno:车牌
     * @param frameno:车架号
     * @param drivingno:行驶证照片
     * @param userflag:密码
     * @param token:验证字符串
     * @param callBack：回调接口
     */
    public void addAcccarhen(String cartype, String carno, String frameno, String engineno,
                             String drivingno, String userflag, String token, String registertime,
                             EntityBean insuranceinfo, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("cartype", cartype);
        bean.set("casecarno", carno);
        bean.set("frameno", frameno);
        bean.set("engineno", engineno);
        bean.set("drivingnoimg", drivingno);
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("registertime", registertime);
        bean.set("insuranceinfo", insuranceinfo);
        run(BASE_URL, URLConstant.ADD_ACCCARHEN, bean, callBack);
    }

    /**
     * 绑定驾驶证
     *
     * @param userflag:用户名
     * @param token:验证字符串
     * @param username:姓名
     * @param cardno:身份证号
     * @param fileno:档案编号
     * @param drivingno:驾驶证照片
     * @param callBack：回调接口
     */
    public void addDriverInfo(String userflag, String token, String username, String cardno,
                              String fileno, String drivingno, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("cardno", cardno);
        bean.set("driverfileno", fileno);
        bean.set("token", token);
        bean.set("name", username);
        bean.set("drivernoimg", drivingno);
        run(BASE_URL, URLConstant.ADD_DRIVERINFO, bean, callBack);
    }

    /**
     * 修改车辆
     *
     * @param id:该条数据的id
     * @param carno:车牌
     * @param frameno:车架号
     * @param drivingno:行驶证照片
     * @param userflag:登录名
     * @param cartype:车辆类型
     * @param token:验证字符串
     * @param callBack：回调接口
     */
    public void modifyCar(String id, String userflag, String carno, String frameno, String engineno,
                          String cartype, String token, String drivingno,
                          String registertime, EntityBean insuranceinfo, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("id", id);
        bean.set("uid", userflag);
        bean.set("casecarno", carno);
        bean.set("frameno", frameno);
        bean.set("engineno", engineno);
        bean.set("cartype", cartype);
        bean.set("token", token);
        bean.set("drivingnoimg", drivingno);
        bean.set("registertime", registertime);
        bean.set("insuranceinfo", insuranceinfo);
        run(BASE_URL, URLConstant.MODIFYCAR, bean, callBack);
    }

    /**
     * 删除车辆信息
     *
     * @param id:车辆id
     * @param userflag:登录名
     * @param token:验证字符串
     * @param callBack：回调接口
     */
    public void deleteCar(String id, String userflag, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("id", id);
        bean.set("uid", userflag);
        bean.set("token", token);
        run(BASE_URL, URLConstant.DELETECAR, bean, callBack);
    }

    /**
     * 修改驾驶证
     *
     * @param cardno:身份证号
     * @param username:姓名
     * @param drivingno:行驶证照片
     * @param userflag:登录名
     * @param driverfileno:档案编号
     * @param token:验证字符串
     * @param callBack：回调接口
     */
    public void modifyDriverinfo(String userflag, String cardno, String username,
                                 String driverfileno, String token,
                                 String drivingno, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("cardno", cardno);
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("name", username);
        bean.set("driverfileno", driverfileno);
        bean.set("drivernoimg", drivingno);
        run(BASE_URL, URLConstant.MODIFY_DRIVERINFO, bean, callBack);
    }

    /**
     * 是否绑定信息
     *
     * @param id：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void bindState(String id, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", id);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.QUERYBINDINGCARS, bean, callBack);
    }

    /**
     * 查询驾驶证信息
     *
     * @param ownername：车主姓名
     * @param uid：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getCarOwner(String ownername, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("carownername", ownername);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.KCKPAPPGETCAROWNER, bean, callBack);
    }

    /**
     * 查询用户绑定的车辆信息
     *
     * @param id：车主姓名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCars(String id, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", id);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.KCKPSEARCHCARS, bean, callBack);
    }

    /**
     * 历史案件
     *
     * @param userId：车牌号
     * @param phone：手机号
     * @param type：案件类型
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchAllCase(String userId, String phone, String type,
                              String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userId);
        bean.set("telephone", phone);
        bean.set("querytype", type);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.ALLCASES, bean, callBack);
    }

    /**
     * 事故详情信息接口
     *
     * @param appcaseno：移动报案号
     * @param phone：手机号
     * @param uid：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void accidentDetails(String appcaseno, String phone, String uid,
                                String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("casenumber", appcaseno);
        bean.set("appphone", phone);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.ACCIDENT_DETAILS, bean, callBack);
    }

    /**
     * 首次登录是否需要一键保险报案
     *
     * @param phone：手机号
     * @param uid：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void insReport(String phone, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("phone", phone);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.INS_REPORT, bean, callBack);
    }

    /**
     * 新登录
     *
     * @param phone：手机号
     * @param callBack：回调接口
     */
    public void isRegister(String phone, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("phone", phone);
        run(KCKP_URL, URLConstant.IS_REGISTER, bean, callBack);
    }

    /**
     * 获取区域id
     *
     * @param longitude：经度
     * @param latitude：纬度
     * @param userflag：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getAreaId(String longitude, String latitude, String userflag,
                          String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("maplon", longitude);
        bean.set("maplat", latitude);
        bean.set("uid", userflag);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.CHECKAREAID, bean, callBack);
    }

    /**
     * 检测时间
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void checkTime(String userflag, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.CHECKTIME, bean, callBack);
    }

    /**
     * 不保险报案，放弃理赔
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void giveupCps(String appno, String userflag, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", appno);
        bean.set("uid", userflag);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.GIVEUP_CPS, bean, callBack);
    }

    /**
     * 反馈
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param name：姓名
     * @param appphone：手机号
     * @param content：反馈意见
     * @param callBack：回调接口
     */
    public void feedback(String userflag, String token, String name, String appphone, String content, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("name", name);
        bean.set("appphone", appphone);
        bean.set("suggestion", content);
        run(KCKP_URL, URLConstant.FEED_BACK, bean, callBack);
    }

    /**
     * 首页新闻查询
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param type：news类型
     * @param callBack：回调接口
     */
    public void searchNews(String userflag, String token, String type, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("newstype", type);
        run(KCKP_URL, URLConstant.SEARCH_NEWS, bean, callBack);
    }

    /**
     * 收藏(取消收藏)新闻
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param id：新闻id
     * @param callBack：回调接口
     */
    public void collectNews(String userflag, String token, String id, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("newsid", id);
        run(KCKP_URL, URLConstant.COLLECT_NEWS, bean, callBack);
    }

    /**
     * 我的收藏列表
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param nextid：新闻id
     * @param pagesize：数目
     * @param callBack：回调接口
     */
    public void collectNewsList(String userflag, String token, String nextid, String pagesize, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("nextid", nextid);
        bean.set("pagesize", pagesize);
        run(KCKP_URL, URLConstant.NEWS_LIST, bean, callBack);
    }

    /**
     * 车主头条
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param nextid：新闻id
     * @param pagesize：数目
     * @param callBack：回调接口
     */
    public void searchMoreNews(String userflag, String token, String newstype, String nextid,
                               String pagesize, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("newstype", newstype);
        bean.set("lastid", nextid);
        bean.set("num", pagesize);
        run(KCKP_URL, URLConstant.SEARCH_MORENEWS, bean, callBack);
    }

    /**
     * 是否收藏该新闻
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param id：新闻id
     * @param callBack：回调接口
     */
    public void checkCollect(String userflag, String token, String id, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("newsid", id);
        run(KCKP_URL, URLConstant.CHECK_COLSTATE, bean, callBack);
    }

    /**
     * 查询该区域下所有产险公司列表
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCplist(String userflag, String token, String carno, String caseno,
                             RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", userflag);
        bean.set("token", token);
        bean.set("casecarno", carno);
        bean.set("appcaseno", caseno);
        run(KCKP_URL, URLConstant.SEARCH_CPLIST, bean, callBack);
    }

    /**
     * 查询该区域下所有产险公司列表
     *
     * @param userflag：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCplist(String userflag, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("username", userflag);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.SEARCH_CPSS, bean, callBack);
    }

    /**
     * 验证车辆的交强险
     *
     * @param caseno：案件编号
     * @param carno：报案车牌号
     * @param phone：报案手机号
     * @param carlist：事故车辆信息
     * @param userflag：用户名
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void checkCarsValid(String caseno, String carno, String phone, EntityBean[] carlist,
                               String userflag, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("casecarno", carno);
        bean.set("appphone", phone);
        bean.set("casecarlist", carlist);
        bean.set("uid", userflag);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.CHECK_CARVALID, bean, callBack);
    }

    /**
     * 保险电话报案
     *
     * @param caseno：案件编号
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void giveupIsass(String caseno, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.GIVEUP_ISASS, bean, callBack);
    }

    /**
     * 验证行驶证
     *
     * @param carno：对方车牌号
     * @param uid：用户id
     * @param frameno：对方车架号
     * @param name：对方姓名，名字里面带测试就可以通过
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void checkDriving(String uid, String token, String carno, String frameno, String name,
                             RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("casecarno", carno);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("frameno", frameno);
        bean.set("name", name);
        run(KCKP_URL, URLConstant.CHECK_DRIVING, bean, callBack);
    }

    /**
     * 查询保单
     *
     * @param carno：对方车牌号
     * @param uid：用户id
     * @param frameno：对方车架号
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCpsNum(String uid, String token, String carno, String frameno, String caseno,
                             RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("casecarno", carno);
        bean.set("frameno", frameno);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("appcaseno", caseno);
        run(KCKP_URL, URLConstant.SEARCH_CPSNUM, bean, callBack);
    }

    /**
     * 验证图片是否全部上传成功
     *
     * @param data：对方车牌号
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void checkImgIsOver(String uid, String token, String data, String caseno, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("data", data);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("appcaseno", caseno);
        run(KCKP_URL, URLConstant.CHECK_IMGOVER, bean, callBack);
    }

    /**
     * 获取审核过的定责图片
     *
     * @param caseno：案件编号
     * @param uid：用户id
     * @param token：验证字符串
     * @param imgType：图片类型：1定责；2定损
     * @param callBack：回调接口
     */
    public void getPasImgUrl(String uid, String token, String caseno, String imgType, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("imgtype", imgType);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("appcaseno", caseno);
        run(KCKP_URL, URLConstant.GET_PASIMGURL, bean, callBack);
    }

    /**
     * 直接报警远程定责
     *
     * @param caseno：案件编号
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void telAlarm(String uid, String token, String caseno, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("appcaseno", caseno);
        run(KCKP_URL, URLConstant.TEL_ALARM, bean, callBack);
    }

    /**
     * 查询全部反馈信息
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getAllSuggests(String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.GET_SUGGESTS, bean, callBack);
    }

    /**
     * 查询理赔中心
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCenters(String caseno, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.KCKPSEARCHCPSCENTER, bean, callBack);
    }

    /**
     * 给保险公司发送图片数据
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param type:0事故的全部照片;1 银行卡信息补传;2对方;3己方;4双方
     * @param callBack：回调接口
     */
    public void submitImageInfo(String caseno, String uid, String token, String type, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("type", type);
        run(KCKP_URL, URLConstant.SUBMIT_IMAGEINFO, bean, callBack);
    }

    /**
     * 选择保险类型
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param type:1.交强险;2.商业险
     * @param callBack：回调接口
     */
    public void saveCpstype(String caseno, String uid, String token, String type, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("username", uid);
        bean.set("password", token);
        bean.set("cpstype", type);
        run(KCKP_URL, URLConstant.SAVE_CPSTYPE, bean, callBack);
    }

    /**
     * 周边事故示警
     *
     * @param latitude:区域id
     * @param time:时间段
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchAccidents(String latitude, String longtitude, String time, String uid, String token,
                                RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("maplat", latitude);
        bean.set("maplon", longtitude);
        bean.set("username", uid);
        bean.set("token", token);
        bean.set("time", time);
        run(KCKP_URL, URLConstant.SEARCH_ACCIDENTS, bean, callBack);
    }

    /**
     * 违章查询
     *
     * @param carnum:车牌号
     * @param carcode:车架号
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchPeccancy(String carnum, String carcode, String engineno, String cartype,
                               String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("carNumber", carnum);
        bean.set("carCode", carcode);
        bean.set("engineno", engineno);
        bean.set("carType", cartype);
        bean.set("token", token);
        bean.set("username", uid);
        run(KCKP_URL, URLConstant.SEARCH_PECCANCY, bean, callBack);
    }

    /**
     * 年检提醒
     *
     * @param carnum:车牌号
     * @param cartype:车辆类型
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void carInspect(String carnum, String time, String cartype, String uid, String token,
                           RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("carNumber", carnum);
        bean.set("time", time);
        bean.set("carType", cartype);
        bean.set("token", token);
        bean.set("username", uid);
        run(KCKP_URL, URLConstant.CAR_INSPECT, bean, callBack);
    }

    /**
     * 天气
     *
     * @param maplon:经度
     * @param maplat:维度
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getWeather(String maplon, String maplat, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("maplon", maplon);
        bean.set("maplat", maplat);
        bean.set("token", token);
        bean.set("username", uid);
        run(KCKP_URL, URLConstant.GET_WEACHER, bean, callBack);
    }

    /**
     * 获取随手拍案件编号
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getSspAreaid(String maplon, String maplat, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("maplon", maplon);
        bean.set("maplat", maplat);
        bean.set("token", token);
        bean.set("uid", uid);
        run(KCKP_URL, URLConstant.GET_AREAID, bean, callBack);
    }

    /**
     * 上传图片信息
     *
     * @param maplon:经度
     * @param maplat:维度
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void submitcaseimg(String caseno, String maplon, String maplat, String address, String filePath,
                              int imgtype, String date, String areaid, String type, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("imagelon", maplon);
        bean.set("imagelat", maplat);
        bean.set("imageaddress", address);
        bean.set("imagetype", imgtype);
        bean.set("imagedate", date);
        bean.set("areaid", areaid);
        bean.set("token", token);
        bean.set("uid", uid);
        bean.set("methodtype", type);
        run(KCKP_URL, URLConstant.UPLOAD_FILE, bean, filePath, callBack);
    }

    /**
     * 上传随手拍信息
     *
     * @param maplon:经度
     * @param maplat:维度
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void submitInfo(String caseno, String carno, String phone, String maplon, String maplat, String place,
                           String street, String cartype, String areaid, String atype, String uname,
                           String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("casecarno", carno);
        bean.set("appphone", phone);
        bean.set("caselon", maplon);
        bean.set("caselat", maplat);
        bean.set("accidentplace", place);
        bean.set("accidentstreet", street);
        bean.set("carnumkind", cartype);
        bean.set("accidenttype", atype);
        bean.set("username", uname);
        bean.set("areaid", areaid);
        bean.set("token", token);
        bean.set("uid", uid);
        run(KCKP_URL, URLConstant.SUBMIT_INFO, bean, callBack);
    }

    /**
     * 随手拍详情
     *
     * @param caseno
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void snapshotDetails(String caseno, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("token", token);
        bean.set("uid", uid);
        run(KCKP_URL, URLConstant.SNAPSHOT_DETAILS, bean, callBack);
    }

    /**
     * 获取我的随手拍
     *
     * @param phone:手机号
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchSnapshot(String phone, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("telephone", phone);
        bean.set("token", token);
        bean.set("uid", uid);
        run(KCKP_URL, URLConstant.SEARCH_SNAPSHOT, bean, callBack);
    }

    /**
     * 查询服务中心
     *
     * @param type:0距离;1评分
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCpsCenter(String caseno, String uid, String token, String type, String longitude, String latitude,
                                RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("querytype", type);
        bean.set("maplon", longitude);
        bean.set("maplat", latitude);
        run(KCKP_URL, URLConstant.SEARCH_CPSCENTER, bean, callBack);
    }

    /**
     * 查询服务中心详情
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void searchCpsCenterDetail(String centerid, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("centerid", centerid);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.GET_CENTERDETAILS, bean, callBack);
    }

    /**
     * 提交评价
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void submitEvaluation(String caseno, EntityBean kcbean, String isonline, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", caseno);
        bean.set("kcbean", kcbean);
        bean.set("token", token);
        bean.set("isonline", isonline);
        bean.set("uid", uid);
        run(KCKP_URL, URLConstant.SUBMIT_CENTEREVALUATION, bean, callBack);
    }

    /**
     * 查询评论
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getCenterEvaluation(String centerid, String uid, String token, int pagenum, int pagesize, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("centerid", centerid);
        bean.set("uid", uid);
        bean.set("token", token);
        bean.set("pagenum", pagenum);
        bean.set("pagesize", pagesize);
        run(KCKP_URL, URLConstant.GET_CENTEREVALUATION, bean, callBack);
    }

    /**
     * 绑定服务中心
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void bindServiceCenter(String appcaseno, String centerid, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", appcaseno);
        bean.set("centerid", centerid);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.BIND_SERVICECENTER, bean, callBack);
    }

    /**
     * 发送短信提示给服务中心
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void sendServiceCenter(String appcaseno, String centerid, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", appcaseno);
        bean.set("centerid", centerid);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.SEND_SERVICECENTER, bean, callBack);
    }

    /**
     * 获取服务中心id
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void getCenterid(String appcaseno, String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("appcaseno", appcaseno);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.GET_SERVICECENTERID, bean, callBack);
    }

    /**
     * 获取服务中心id
     *
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void savePVInfo(String uid, String token, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("ip", "");
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.SAVE_PVINFO, bean, callBack);
    }

    /**
     * 获取服务中心id
     *
     * @param type：1.快处;2.快赔
     * @param uid：用户id
     * @param token：验证字符串
     * @param callBack：回调接口
     */
    public void checkTimeIsWork(String uid, String token, String type, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("type", type);
        bean.set("uid", uid);
        bean.set("token", token);
        run(KCKP_URL, URLConstant.CHECK_TIMEISWORK, bean, callBack);
    }

    /**
     * 上传文件
     *
     * @param bean
     * @param type:2-协会版现场照片上传接口;3-协会版定损照片上传接口
     * @param filePath:文件的路径
     * @param callBack
     */
    public void uploadFile(EntityBean bean, String type, String filePath, RequestCallBack callBack) {
        if (bean == null) {
            return;
        }
        bean.set("methodtype", type);
        run(KCKP_URL, URLConstant.UPLOAD_FILE, bean, filePath, callBack);
    }

    /**
     * 执行网络请求
     */
    private void run(String url, String serviceName, EntityBean bean, final RequestCallBack callBack) {
        LoadDataManagerCar.getInstance(mContext).callService(null, url, serviceName, bean,
                new LoadDataManagerFather.OnRequestCompleteListener() {
                    @Override
                    public void onSuccess(String key, String service, final Object result) {
                        if (BuildConfig.DEBUG) {
                            StringBuffer success = new StringBuffer();
                            success.append("onSuccess--->");
                            success.append(result.toString());
                            Log.i(service, success.toString());
                        }
                        if (null != callBack) {
                            callBack.onSuccess(result);
                        }
                    }

                    @Override
                    public void onError(String key, String service, final LoadDataManagerFather.ResultType resultType) {
                        if (BuildConfig.DEBUG) {
                            StringBuffer error = new StringBuffer();
                            error.append("onError--->");
                            error.append(resultType.toString());
                            Log.i(service, error.toString());
                        }
                        if (null != callBack) {
                            if (resultType == LoadDataManagerFather.ResultType.Failure) {
                                callBack.onError("网络服务故障，请稍后重试");
                            } else if (resultType == LoadDataManagerFather.ResultType.NoNetWorks) {
                                callBack.onError("无网络连接，请检查您的网络");
                            } else {
                                callBack.onError(null);
                            }
                        }
                    }

                    @Override
                    public void onFinished(String key, String service) {

                    }
                });
    }

    /**
     * 执行网络请求
     */
    private void run(String url, String serviceName, EntityBean bean, String filePath, final RequestCallBack callBack) {
        LoadDataManager4 manager = LoadDataManager4.getInstance(mContext);
        //设置用户被挤掉的标记值，参数为字符串数组
        manager.setLoginOutArray(new String[]{"-1", "-2", "-3", "-4", "-6", "-7"});
        //设置用户Session超时标记符，参数为字符串数组
        manager.setSessionTimeOutArray(new String[]{"-5"});
        manager.callService3(null, url, serviceName, bean, false, "imagefile", new File(filePath),
                "application/octet-stream", new LoadDataManagerFather.OnuploadFileLishtener() {
                    @Override
                    public void onUpload(long cuttrnt, long total) {

                    }
                }, new LoadDataManagerFather.OnRequestCompleteListener() {
                    @Override
                    public void onSuccess(String key, String service, final Object result) {
                        if (BuildConfig.DEBUG) {
                            StringBuffer success = new StringBuffer();
                            success.append("onSuccess--->");
                            success.append(result.toString());
                            Log.i(service, success.toString());
                        }
                        if (null != callBack) {
                            callBack.onSuccess(result);
                        }
                    }

                    @Override
                    public void onError(String key, String service, final LoadDataManagerFather.ResultType resultType) {
                        if (BuildConfig.DEBUG) {
                            StringBuffer error = new StringBuffer();
                            error.append("onError--->");
                            error.append(resultType.toString());
                            Log.i(service, error.toString());
                        }
                        if (null != callBack) {
                            if (resultType == LoadDataManagerFather.ResultType.Failure) {
                                callBack.onError("网络服务故障，请稍后重试");
                            } else if (resultType == LoadDataManagerFather.ResultType.NoNetWorks) {
                                callBack.onError("无网络连接，请检查您的网络");
                            } else {
                                callBack.onError(null);
                            }
                        }
                    }

                    @Override
                    public void onFinished(String key, String service) {

                    }
                });
    }

    /**
     * 网络请求的回调接口
     */
    public interface RequestCallBack {

        void onError(String error);

        void onSuccess(Object result);
    }

    /**
     * 定责定损
     *
     * @param phonenum:手机号码
     * @param callBack：回调接口
     */
    public void getAgreementCode(String phonenum, String codeType, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("mobilephone", phonenum);
        bean.set("contenttype", codeType);
        run(BASE_URL, URLConstant.KCKPAPPSENDVERCODE, bean, callBack);
    }

    /**
     * 驾驶证和行驶证图像识别
     *
     * @param photo    图像的String
     * @param type     2-二代身份证正面，3-二代身份证反面 5-驾驶证 6-行驶证
     * @param callBack
     */
    public void getOcrInfo(String photo, String type, RequestCallBack callBack) {
        EntityBean bean = new EntityBean();
        bean.set("image", photo);
        bean.set("username", "HNKCKP");
        bean.set("userkey", "henankckp");
        bean.set("type", type);
        run(BASE_URL, URLConstant.OCR_INFO, bean, callBack);
    }

}